package com.campus.manage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.campus.common.annotation.Log;
import com.campus.common.core.controller.BaseController;
import com.campus.common.core.domain.AjaxResult;
import com.campus.common.enums.BusinessType;
import com.campus.manage.domain.NewsType;
import com.campus.manage.service.INewsTypeService;
import com.campus.common.utils.poi.ExcelUtil;
import com.campus.common.core.page.TableDataInfo;

/**
 * 新闻类型Controller
 * 
 * @author hehe
 * @date 2025-10-22
 */
@RestController
@RequestMapping("/manage/type")
public class NewsTypeController extends BaseController
{
    @Autowired
    private INewsTypeService newsTypeService;

    /**
     * 查询新闻类型列表
     */
    @PreAuthorize("@ss.hasPermi('manage:type:list')")
    @GetMapping("/list")
    public TableDataInfo list(NewsType newsType)
    {
        startPage();
        List<NewsType> list = newsTypeService.selectNewsTypeList(newsType);
        return getDataTable(list);
    }

    /**
     * 导出新闻类型列表
     */
    @PreAuthorize("@ss.hasPermi('manage:type:export')")
    @Log(title = "新闻类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NewsType newsType)
    {
        List<NewsType> list = newsTypeService.selectNewsTypeList(newsType);
        ExcelUtil<NewsType> util = new ExcelUtil<NewsType>(NewsType.class);
        util.exportExcel(response, list, "新闻类型数据");
    }

    /**
     * 获取新闻类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:type:query')")
    @GetMapping(value = "/{typeId}")
    public AjaxResult getInfo(@PathVariable("typeId") Long typeId)
    {
        return success(newsTypeService.selectNewsTypeByTypeId(typeId));
    }

    /**
     * 新增新闻类型
     */
    @PreAuthorize("@ss.hasPermi('manage:type:add')")
    @Log(title = "新闻类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NewsType newsType)
    {
        return toAjax(newsTypeService.insertNewsType(newsType));
    }

    /**
     * 修改新闻类型
     */
    @PreAuthorize("@ss.hasPermi('manage:type:edit')")
    @Log(title = "新闻类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NewsType newsType)
    {
        return toAjax(newsTypeService.updateNewsType(newsType));
    }

    /**
     * 删除新闻类型
     */
    @PreAuthorize("@ss.hasPermi('manage:type:remove')")
    @Log(title = "新闻类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{typeIds}")
    public AjaxResult remove(@PathVariable Long[] typeIds)
    {
        return toAjax(newsTypeService.deleteNewsTypeByTypeIds(typeIds));
    }
}
